package com.aaa.whj.Controller;

import com.aaa.whj.Service.StudentService;
import com.aaa.whj.entity.Student;
import com.aaa.whj.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: whj
 * @Version 1.0
 * @Date: 2022/11/15  9:46
 */
@RestController
@Api(tags = "学生操作 ")
public class StudentController {
    @Autowired
    private StudentService studentService;

    @ApiOperation(value = "查询")
    @GetMapping("select")
    @ResponseBody
    @ApiImplicitParams({                /*defaultValue = "1",  默认值*/
            @ApiImplicitParam(name = "currentPage",required = true,value = "当前页",dataType = "int"),
            @ApiImplicitParam(name = "pageSize", required = true,value = "数量",dataType = "int")
    })
    public Result select(@RequestParam(defaultValue = "1") Integer currentPage, @RequestParam(defaultValue = "5") Integer pageSize){
        return studentService.selectAll(currentPage, pageSize);
    }

    @ApiOperation(value = "添加")
    @PostMapping("add")
    @ResponseBody
    public Result add(@RequestBody Student student){
        return studentService.addStudent(student);
    }

    @ApiOperation(value = "修改")
    @PutMapping("update")
    @ResponseBody
    public Result update(@RequestBody Student student){
        return studentService.updateStudent(student);
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("delete")
    @ResponseBody
    public Result delete(Integer id){
        return studentService.deleteStudent(id);
    }
}
